<!DOCTYPE html>
<html xmlns:th="http://www.theymeleaf.org">
<head>
    <meta charset="utf-8">
    <title>列表</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="/layui/css/layui.css" media="all"/>
    <link rel="stylesheet" href="/css/font_eolqem241z66flxr.css"
          media="all"/>
    <link rel="stylesheet" href="/css/news.css" media="all"/>
    <script type="text/javascript" src="/layui/layui.js"></script>
</head>
<body class="childrenBody">
<blockquote class="layui-elem-quote news_search">
    <div class="layui-inline">
        <a class="layui-btn layui-btn-danger" data-type="dels">批量删除</a>
    </div>

</blockquote>
<table id="list" lay-filter="listtable"></table>
<script type="text/html" id="listtable-opt">
    <a class="layui-btn layui-btn-xs" lay-event="tg">同意</a>
    <a class="layui-btn layui-btn-xs" lay-event="jj">拒绝</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>
<script type="text/javascript" th:inline="none">

    var reloadList = function () {
        layui.use(['layer'], function () {
            var $ = layui.juery, layer = layui.layer;
            layer.closeAll();
            loadList(true);
        });
    }
    layui.use('layer', function () {
        var $ = layui.juery, layer = layui.layer;
        var index = '';
        reloadList(true);

    });
    var resetSwClose = function (isClose) {
        layui.use(['layer'], function () {
            var $ = layui.jquery, layer = layui.layer;// 独立版的layer无需执行这一句
            if (isClose) {
                $('.layui-layer-setwin a.layui-layer-close1').hide();
            } else {
                $('.layui-layer-setwin a.layui-layer-close1').show();
            }
        });
    }

    var loadList = function (first) {
        layui
            .config({
                base: "js/"
            })
            .use(
                ['form', 'layer', 'jquery', 'laypage', 'table'],
                function () {
                    var form = layui.form, layer = layui.layer, laypage = layui.laypage, $ = layui.jquery;
                    var table = layui.table;

                    function getUParam(name, id) {
                        var reg = new RegExp("(^|&)" + name
                            + "=([^&]*)(&|$)"); // 构造一个含有目标参数的正则表达式对象
                        var r = decodeURIComponent(
                            $("#" + id).attr("src").substr(
                                $("#" + id).attr("src")
                                    .indexOf("?")).substr(1))
                            .match(reg); // 匹配目标参数
                        if (r != null)
                            return unescape(r[2]);
                        return ""; // 返回参数值
                    }

                    // 第一个实例
                    table.render({
                        elem: '#list',
                        url: '/yyjl/pagegetall' // 数据接口
                        ,
                        cols: [[ // 表头
                            {
                                type: 'checkbox',
                                fixed: 'left'
                            }, {
                                field: 'uname',
                                title: '预约人'
                            },{
                                field: 'tel',
                                title: '电话'
                            }, {
                                field: 'startaddress',
                                title: '开始地址'
                            }, {
                                field: 'endaddress',
                                title: '结束地址'
                            }, {
                                field: 'cph',
                                title: '车牌号'
                            }, {
                                field: 'state',
                                title: '状态'
                            },{
                                field: 'time',
                                title: '申请时间',
                            },
                            {
                                fixed: 'right',
                                title: '操作',
                                width: 160,
                                templet: '#listtable-opt',
                                align: 'center'
                            }]],
                        height: 'full-80',
                        page: true,
                        limits: [10, 15, 25, 40, 60, 80, 100, 120, 140]
                        // 开启分页
                    });
                    // 添加文章
                    $(".add").click(function () {

                    });
                    // 监听工具条
                    table.on('tool(listtable)', function (obj) {
                        var that = this;
                        var data = obj.data;
                        var idDatas = "id='" + data.id + "'";
                        var idData = "id=" + data.id + "";
                        if (obj.event === 'del') {
                            layer.confirm('你确认删除这条数据吗?', function (index) {
                                $.getJSON("/yyjl/del", idDatas,
                                    function (jsondata) {
                                        if (jsondata.code == '200') {
                                            layer.msg('删除数据成功', {
                                                time: 1000,
                                                shade: [0.001,
                                                    '#ffffff']
                                            }, function () {
                                                reloadList();
                                            });
                                        } else {
                                            layer.msg(jsondata.msg, {
                                                time: 2000
                                            });
                                        }
                                    });
                            });
                        } else if (obj.event === 'tg') {
                            $.getJSON("/yyjl/update_state?state=同意", idData,
                                function (jsondata) {
                                    if (jsondata.code == '200') {
                                        layer.msg('同意', {
                                            time: 1000,
                                            shade: [0.001,
                                                '#ffffff']
                                        }, function () {
                                            reloadList();
                                        });
                                    } else {
                                        layer.msg(jsondata.msg, {
                                            time: 2000
                                        });
                                    }
                                });
                        }else if (obj.event === 'jj') {
                            $.getJSON("/yyjl/update_state?state=拒绝", idData,
                                function (jsondata) {
                                    if (jsondata.code == '200') {
                                        layer.msg('拒绝', {
                                            time: 1000,
                                            shade: [0.001,
                                                '#ffffff']
                                        }, function () {
                                            reloadList();
                                        });
                                    } else {
                                        layer.msg(jsondata.msg, {
                                            time: 2000
                                        });
                                    }
                                });
                        }
                    });

                    var $ = layui.$, active = {
                        add: function () { // 获取选中数据
                            index = layer.open({
                                title: "添加用户",
                                type: 2,
                                area: ['100%', '100%'],
                                content: "/yyjl/toadd"
                            });

                        },
                        dels: function () { // 获取选中数目
                            var checkStatus = table.checkStatus('list'), data = checkStatus.data;
                            var len = data.length;
                            var idDatas = "";
                            for (var i = 0, l = len; i < l; i++) {
                                if (i == 0) {
                                    idDatas += "id='" + data[i].id + "'"
                                } else {
                                    idDatas += "&id='" + data[i].id + "'"
                                }
                            }
                            if (len == 0) {
                                layer.msg('请选择您将要删除的记录', {
                                    time: 2000
                                });
                                return false;
                            } else {
                                var info = '些';
                                if (len == 1)
                                    info = '条';
                                layer
                                    .confirm(
                                        '你确认删除这' + info + '记录吗？',
                                        {
                                            btn: ['确认', '取消']
                                            // 按钮
                                        },
                                        function (index) {
                                            $
                                                .getJSON(
                                                    ctxPath
                                                    + "/yyjl/del",
                                                    idDatas,
                                                    function (
                                                        jsondata) {
                                                        if (jsondata.code == '200') {
                                                            layer
                                                                .msg(
                                                                    '删除数据成功',
                                                                    {
                                                                        time: 1000,
                                                                        shade: [
                                                                            0.001,
                                                                            '#ffffff']
                                                                    },
                                                                    function () {
                                                                        reloadList();
                                                                    });
                                                        } else {
                                                            layer
                                                                .msg(
                                                                    jsondata.msg,
                                                                    {
                                                                        time: 2000
                                                                    });
                                                        }
                                                    });
                                        });
                            }
                        },
                        del: function () { // 验证是否全选
                            var checkStatus = table.checkStatus('idTest');
                            layer.msg(checkStatus.isAll ? '全选' : '未全选')
                        }
                    };
                    $('.layui-btn').on('click', function () {
                        var type = $(this).data('type');
                        active[type] ? active[type].call(this) : '';
                    });
                    // 全选
                    form
                        .on(
                            'checkbox(allChoose)',
                            function (data) {
                                var child = $(data.elem)
                                    .parents('table')
                                    .find(
                                        'tbody input[type="checkbox"]:not([name="show"])');
                                child
                                    .each(function (index, item) {
                                        item.checked = data.elem.checked;
                                    });
                                form.render('checkbox');
                            });

                    // 通过判断文章是否全部选中来确定全选按钮是否选中
                    form
                        .on(
                            "checkbox(choose)",
                            function (data) {
                                var child = $(data.elem)
                                    .parents('table')
                                    .find(
                                        'tbody input[type="checkbox"]:not([name="show"])');
                                var childChecked = $(data.elem)
                                    .parents('table')
                                    .find(
                                        'tbody input[type="checkbox"]:not([name="show"]):checked')
                                if (childChecked.length == child.length) {
                                    $(data.elem)
                                        .parents('table')
                                        .find(
                                            'thead input#allChoose')
                                        .get(0).checked = true;
                                } else {
                                    $(data.elem)
                                        .parents('table')
                                        .find(
                                            'thead input#allChoose')
                                        .get(0).checked = false;
                                }
                                form.render('checkbox');
                            });
                });
    }


</script>
</body>
</html>